<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * FormativeLab
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		FormativeLab
 * @author		FormativeLab Dev Team
 * @copyright	Copyright (c) 2011 - 2013, FormativeLab, Inc.
 * @license		http://www.formativesoft.com/license/
 * @link		http://www.formativesoft.com/
 * @since		Version 2.0
 * @filesource ./application/models/m01001/m01i001/m01i010001.php
 */

// ------------------------------------------------------------------------

/**
 * FormativeLab M01I010001 Model
 *
 * @package		FormativeLab
 * @subpackage	model
 * @category	model
 * @author		Formative Soft Ltd
 * @link		http://www.formativesoft.com/
 */

// ------------------------------------------------------------------------

class M01I010001 extends FSL_Model implements Repository, PrePostCrudListener, ResponseData {

    public $id;
    public $nameEn;
    public $nameBn;
	public $districtCode;
	
	public $district;
	
	const ENTITY      = 't01i010';
	const ID_FIELD    = 'f_municipal_code';

	/**
	 * Entity class mapping with RDMS Table. This static property use to map entity
	 * properties with table columns/fields.
	 **/
	static $mapping   = array(
		'id'    => array(
			'name'	 => self::ID_FIELD,			
			'jsname' => 'id',
			'jstype' => 'int',
		),
		'nameEn'  => array(
			'name'	 => 'f_name_en',
			'jsname' => 'nameEn',
			'jstype' => 'string',
		),
		'nameBn' => array(
			'name'	 => 'f_name_bn',
			'jsname' => 'nameBn',
			'jstype' => 'string'
		),
		'districtCode' => array(
			'name'	 => 'k_district_code',
			'jsname' => 'districtCode',
			'jstype' => 'string'
		)
	);

	/**
	 * static property constraints declaration
	 **/
	static $constraints	= array(
		'nameEn'  => array(
			'NAME_EN_RE'	=>	'm01i010001.nameEn'
		),
		'nameBn'  => array(
			'NAME_BN_OP'	=>	'm01i010001.nameBn'
		)
	);
	
	/**
	 * __construct() Method is an empty constructor. This method use to
	 * initialization of entity/domain/model
	 *
	 * Returns void
	 *
	 * @access	public
	 * @return  void 
	 **/
    public function __construct(){
        parent::__construct();
		parent::setEntity($this);
		$this->setLocal('english');
    }
	
	/**
	 * getDistrict() to load belongs to parent entity District's object. This
	 * method load District's object when it's called by user.
	 *
	 * @access	public
	 * @return  M01I007001
	 **/
	public function getDistrict(){
		if($this->districtCode){
			$this->district = &$this->M01I007001->findById($this->districtCode);
		}
		return $this->district;
	}
	
	/**
	 * jget() with an required parameter use to response json object of M01I010001.
	 * This method is use for Extjs 4.1 data package.
	 *
	 * @access	public
	 * @param	id
	 * @return  void
	 **/
	public function jget($id){
		$this->setJsonRender(true);
		$records 	= &$this->get($id);
		$this->jsonRender($records, 1, true);
	}
	
	/**
	 * jfindById() with an required parameter use to response json object of M01I010001.
	 * This method is use for Extjs 4.1 data package.
	 *
	 * @access	public
	 * @param	id
	 * @return  void
	 **/
	public function jfindById($id){
		$this->setJsonRender(true);
		$records 	= &$this->findById($id);
		$this->jsonRender($records, 1, true);
	}
	
	/**
	 * jall() with an required parameter use to response json object of array of M01I010001.
	 * This method is use for Extjs 4.1 data package.
	 *
	 * @access	public
	 * @param	limit
	 * @param	offset
	 * @return  void
	 **/
	public function jall($limit = self::FETCH_LIMIT, $offset = 0){
		$where 		= array();
		$join		= array();
		$count		= $this->count($where, $join);
        $records 	= $this->findAllWhere($where, $join, $limit, $offset);

		$this->setJsonRender(true);
		$this->afterSelect(FslCrudEvent::init($records, 'afterSelect'));
		$this->jsonRender($records, $count, true);	
    }
	
	/**
	 * all() with two parameters, first one is required and another one is optional
	 * use to fetch object of array of M01I010001 from an specific offset and default
	 * fetch limit is 100.
	 *
	 * @access	public
	 * @param	limit
	 * @param	offset
	 * @return  array
	 **/	
    public function all($limit = self::FETCH_LIMIT, $offset = 0){
		$where 	= array();
		$join	= array();
        return $this->findAllWhere($where, $join, $limit, $offset);
    }
	
	/**
	 * findAll() with two parameters, first one is required and another one is optional
	 * use to fetch object of array of M01I010001 from an specific offset and default
	 * fetch limit is 100.
	 *
	 * @access	public
	 * @param	limit
	 * @param	offset
	 * @return  array
	 **/
	public function findAll($limit = self::FETCH_LIMIT, $offset = 0){
		$where 	= array( 
			'nameEn' => array(
				'operator' 	=> 'like',
				'value'		=> 'y',
				'match'		=> 'after'
			)
		);
		$join	= array();
        return $this->findAllWhere($where, $join, $limit, $offset);
    }
	
}

/* End of file m01i010001.php */
/* Location: ./application/models/m01001/m01i001/m01i010001.php */